package com.syni.mdd.yhd.common.all.service;

import com.syni.mdd.yhd.common.all.constants.Constants;
import com.syni.mdd.yhd.common.all.dao.jpa.MtHdAppLoginDao;
import com.syni.mdd.yhd.common.all.entity.BmsUserBusinessAuth;
import com.syni.mdd.yhd.common.all.entity.MtHdAppLogin;
import com.syni.mdd.yhd.common.all.service.impl.BaseService;
import com.syni.mdd.sjb.common.component.utils.common.utils.ResultMapHelper;
import org.apache.tomcat.util.bcel.classfile.Constant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.Map;

/**
 * @className
 * @description TOO
 * @Author cfx
 * @DATE 2019/4/9 12:04
 * @VERSION 1.0
 **/
@Service
public class MtHdAppLoginService extends BaseService<MtHdAppLogin,String> {
    @Autowired
    BmsUserBusinessAuthService bmsUserBusinessAuthService;

    @Autowired
    MtHdAppLoginDao mtHdAppLoginDao;

    @Override
    public MtHdAppLoginDao getBaseDao() {
        return mtHdAppLoginDao;
    }

    public Map<String, Object> createRecord(Integer userId) {
        //寻找该用户认领的商家
        BmsUserBusinessAuth bmsUserBusinessAuth = bmsUserBusinessAuthService.findByUserId(userId);
        if(bmsUserBusinessAuth == null || bmsUserBusinessAuth.getBmsBusiness() == null){
            return ResultMapHelper.failure("请先认领商家");
        }
        Integer businessId = bmsUserBusinessAuth.getBmsBusiness().getId();
        MtHdAppLogin mtHdAppLogin = new MtHdAppLogin();
        mtHdAppLogin.setUserId(businessId);
        mtHdAppLogin.setCreateTime(new Date());
        mtHdAppLogin.setIsDelete(Constants.COMMON_FLAG_FALSE + Constants.COMMON_FLAG_FALSE);
        mtHdAppLoginDao.save(mtHdAppLogin);
        return ResultMapHelper.success(mtHdAppLogin,"ok！");
    }
}
